<?php
session_start();

if(isset($_POST["login"])){
	include("/class.login.php");
	$login = new Login();
	
	if($login->isLoggedIn()){
		$msg = "Je bent ingelogd!";
	}
	else{
		foreach ($login->errors as $key=>$value){
			$errors = $value.", ";
		}
		$msg = "Errors: ".$errors;
	}
}

if(isset($_POST["logout"])){
	session_destroy();
	$msg = "Je bent uitgelogd.";
	header("login.php");
}

$_SESSION['token'] = $token =  md5(uniqid(mt_rand(),true));
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Login</title>
<link href="../css/login.css" rel="stylesheet" type="text/css" />

</head>

<body>
<div id="maincontainer">
  <div id="loginfrm">
    <form action="login.php" method="post">
      <table>
        <tr><td>&nbsp;</td><td><h2>Inloggen</h2></td></tr>
        <tr><td></td><td><?php print($msg); ?></td></tr>
        <tr><td>Gebruikersnaam:</td><td><input type="text" name="username" class="invoer"/></td></tr>
        <tr><td>Paswoord:</td><td><input type="password" name="password" class="invoer"/></td></tr>
        <tr><td>&nbsp;</td><td><input type="hidden" name="token" value="<?php echo $token; ?>" /></td></tr>
        <tr><td>&nbsp;</td><td><input type="submit" name="login" value="Log in" /> <input type="submit" name="logout" value="Log out" /></td></tr>
      </table>
    </form>
  </div>
</div>

</body>
</html>